package appconfig

import (
	"fmt"
	"github.com/spf13/viper"
)

var Config AppConfig

type AppConfig struct {
	Mysql
	Redis
	QiNiuYun
}
type Mysql struct {
	Host     string
	Port     int
	User     string
	Password string
	Database string
}

type Redis struct {
	Addr     string
	Password string
	Database int
}
type QiNiuYun struct {
	AK     string
	SK     string
	Bucket string
	Url    string
}

func Init() {
	viper.SetConfigFile("../appconfig/dev.yaml")
	if err := viper.ReadInConfig(); err != nil {
		panic(err)
	}
	if err := viper.Unmarshal(&Config); err != nil {
		panic(err)
	}
	fmt.Println("配置文件获取成功:", Config)
}
